package com.sky.controller.admin;

import com.sky.Result.PageResult;
import com.sky.Result.Result;
import com.sky.model.dto.ShopDTO;
import com.sky.model.dto.ShopPageQueryDTO;
import com.sky.service.ShopService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@CrossOrigin
public class ShopController {
    @Autowired
    ShopService shopService;

    /**
     * 商品分页查询
     * @param shopPageQueryDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(@RequestBody ShopPageQueryDTO shopPageQueryDTO) {
        log.info("分页查询：{}", shopPageQueryDTO);
        PageResult pageResult = shopService.pageQuery(shopPageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 新增商品
     * @param shopDTO
     * * @return
     * */
    @PostMapping("/save")
    @ApiOperation("新增商品")
    public Result save(@RequestBody ShopDTO shopDTO){
        log.info("新增商品：{}", shopDTO);
        shopService.save(shopDTO);
        return Result.success();
    }
    /**
     * 修改商品
     * @param shopDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改商品")
    public Result update(@RequestBody ShopDTO shopDTO){
        log.info("修改商品：{}", shopDTO);
        shopService.update(shopDTO);
        return Result.success();
    }

    /**
     * 批量启用禁用商品
     * @param ids
     * @return
     */
    @PostMapping("/status")
    @ApiOperation("批量启用禁用商品")
    public  Result startOrstops (@RequestBody List<Long> ids){
        log.info("批量启用禁用商品，ids:{}",ids);
        shopService.startOrstops(ids);
        return Result.success();
    }

    /**
     * 批量删除商品
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("删除商品")
    public  Result delete (@RequestBody List<Long> ids){
        log.info("批量删除操作，ids:{}",ids);
        shopService.delete(ids);
        return Result.success();
    }

    /**
     * 启用禁用商品
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result<String> startOrStop(@PathVariable Integer status,long id){
        log.info("启用禁用商品：{},{}",status,id);
        shopService.startOrstop(status,id);
        return Result.success();
    }
}